﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace StageToDo.Entity.Data
{
    public partial class StageToDoContext : DbContext
    {
        public virtual DbSet<List> List { get; set; }
        public virtual DbSet<ToDoOption> ToDoOption { get; set; }
        public virtual DbSet<User> User { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
            optionsBuilder.UseMySql(@"server=112.74.91.17;uid=root;pwd=123456;database=StageToDo;charset=utf8;");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<List>(entity =>
            {
                entity.HasIndex(e => e.Email)
                    .HasName("FK_Reference_1");

                entity.Property(e => e.ListId).HasColumnType("bigint(20)");

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Email).HasColumnType("varchar(25)");

                entity.Property(e => e.ListName).HasColumnType("varchar(20)");

                entity.HasOne(d => d.EmailNavigation)
                    .WithMany(p => p.List)
                    .HasForeignKey(d => d.Email)
                    .HasConstraintName("FK_Reference_1");
            });

            modelBuilder.Entity<ToDoOption>(entity =>
            {
                entity.HasKey(e => e.OptionId)
                    .HasName("PK_ToDoOption");

                entity.HasIndex(e => e.ListId)
                    .HasName("FK_Reference_2");

                entity.Property(e => e.OptionId).HasColumnType("bigint(20)");

                entity.Property(e => e.ExpirationDate).HasColumnType("datetime");

                entity.Property(e => e.IsCompleted).HasColumnType("bit(1)");

                entity.Property(e => e.ListId).HasColumnType("bigint(20)");

                entity.Property(e => e.OptionContent).HasColumnType("varchar(100)");

                entity.Property(e => e.Remarks).HasColumnType("varchar(100)");

                entity.HasOne(d => d.List)
                    .WithMany(p => p.ToDoOption)
                    .HasForeignKey(d => d.ListId)
                    .HasConstraintName("FK_Reference_2");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.HasKey(e => e.Email)
                    .HasName("PK_User");

                entity.Property(e => e.Email).HasColumnType("varchar(25)");

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Nickname).HasColumnType("varchar(15)");

                entity.Property(e => e.Password).HasColumnType("varchar(15)");

                entity.Property(e => e.UserAvatar).HasColumnType("varchar(60)");
            });
        }
    }
}